/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-07-23     Tian Yiqing  the first version
 */

#ifndef __DRV_I2C_HW__
#define __DRV_I2C_HW__

#include <rtthread.h>
#include <rthw.h>
#include <rtdevice.h>
#include <board.h>
#include "drv_dma.h"

#ifdef __cplusplus
extern "C" {
#endif

#define RT_I2C_DEV_CTRL_CHECK_STANDBY  (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x06)

struct gd32_hw_i2c
{
    uint32_t i2c_periph;          
    rcu_periph_enum per_clk;        
    rcu_periph_enum scl_gpio_clk;    
    rcu_periph_enum sda_gpio_clk;    
    uint32_t scl_port;               
#if defined SOC_SERIES_GD32F4xx
    uint16_t scl_af;                 
#endif
    uint16_t scl_pin;  

    uint32_t sda_port;               
#if defined SOC_SERIES_GD32F4xx
    uint16_t sda_af;                 
#endif
    uint16_t sda_pin;                

    uint32_t address;
    char *device_name;
#if defined BSP_USING_I2C_DMA
    struct dma_config *dma_tx;
    struct dma_config *dma_rx;

    struct rt_completion dma_tx_compl;
    struct rt_completion dma_rx_compl;
#endif
    struct rt_i2c_bus_device bus;
};

#ifdef __cplusplus
}
#endif

#endif /* __DRV_I2C_HW__ */
